package com.xiaoxing.zhinenghuacangku.mvp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dothantech.printer.IDzPrinter;
import com.xiaoxing.zhinenghuacangku.R;

import java.util.List;

/**
 * @author 小星 QQ:753940262
 * @class describe
 * @time 2018/12/26 0026 9:38
 */
// 用于填充打印机列表的Adapter
public class DeviceListAdapter extends BaseAdapter {
    private TextView tv_name = null;
    private TextView tv_mac = null;
    private List<IDzPrinter.PrinterAddress> mPrinterAddresses;
    private Context mContext;

    public DeviceListAdapter(Context context, List<IDzPrinter.PrinterAddress> printerAddresses) {
        this.mContext = context;
        this.mPrinterAddresses = printerAddresses;
    }


    @Override
    public int getCount() {
        return mPrinterAddresses.size();
    }

    @Override
    public Object getItem(int position) {
        return mPrinterAddresses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.zhi_neng_cang_ku_printer_item, null);
        }
        tv_name = (TextView) convertView.findViewById(R.id.tv_device_name);
        tv_mac = (TextView) convertView.findViewById(R.id.tv_macaddress);

        if (mPrinterAddresses != null && mPrinterAddresses.size() > position) {
            IDzPrinter.PrinterAddress printer = mPrinterAddresses.get(position);
            tv_name.setText(printer.shownName);
            tv_mac.setText(printer.macAddress);
        }

        return convertView;
    }
}
